// 防抖
export function _debounce(fn, delayArg) {
    var delay = delayArg || 200;
    var timer;
    return function () {
        var th = this;
        var args = arguments;
        if (timer) {
            clearTimeout(timer);
        }
        timer = setTimeout(function () {
            timer = null;
            fn.apply(th, args);
        }, delay);
    };
}
// 节流
export function _throttle(fn, intervalArg) {
    var last;
    var timer;
    var interval = intervalArg || 200;
    return function () {
        var th = this;
        var args = arguments;
        var now = +new Date();
        if (last && now - last < interval) {
            clearTimeout(timer);
            timer = setTimeout(function () {
                last = now;
                fn.apply(th, args);
            }, interval);
        } else {
            last = now;
            fn.apply(th, args);
        }
    }
}
// 米转千米保留一位小数
export function formatMile(number) {
    return number ? Math.floor(number/100)/10 : 0;
}

const formatNumber = n => {
    n = n.toString()
    return n[1] ? n : '0' + n
}

//时间戳转换 Datetime yyyy/MM/dd hh:mm:ss
export function getDateTimeFormat(shijianchuo) {
    if (shijianchuo != null && shijianchuo != "" && shijianchuo != undefined) {
      var date = new Date(new Date(parseInt(shijianchuo.substr(6, 19))));
      var Y = date.getFullYear() + '/';
      var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/';
      var D = formatNumber(date.getDate()) + ' ';
      var h = formatNumber(date.getHours()) + ':';
      var m = formatNumber(date.getMinutes()) + ':';
      var s = formatNumber(date.getSeconds());
      return Y + M + D + h + m + s;
    } else {
      return "";
    }
  }
  